
<template>
  <div>
    <view
      class="fun-cell"
      :class="customClass"
      :style="customStyle"
      @click="onClick"
    >
      <div class="fun-cell__left-icon-wrap">
        <layout-icon v-if="icon" :type="icon"></layout-icon>
        <slot v-else name="icon"/>
      </div>

      <view
        :style="(titleWidth ? 'max-width:' + titleWidth + ';min-width:' + titleWidth + ';' : '') + titleStyle"
        class="fun-cell__title title-class"
      >
        <block v-if="title">{{ title }}</block>
        <slot v-else name="title" />

        <view v-if="label || useLabelSlot" class="fun-cell__label label-class">
          <slot v-if="useLabelSlot" name="label"/>
          <block v-else-if="label">{{ label }}</block>
        </view>
      </view>

      <view class="fun-cell__value value-class">
        <block v-if="value || value === 0">{{ value }}</block>
        <slot v-else />
      </view>

      <layout-icon
        v-if="isLink"
        :type="arrowDirection ? arrowDirection : 'icon-icon-arrow-right-copy'"
        class="fun-cell__right-icon-wrap right-icon-class"
        custom-class="fun-cell__right-icon"
      />
      <slot v-else name="right-icon"/>
      <slot name="extra"/>
    </view>
  </div>
</template>

<script>
import LayoutIcon from '@/components/layout-icon/layout-icon'
import { linkToEasy } from '@/common/fun'
export default {
  name: 'fun-cell',
  components: { LayoutIcon },
  props: {
    title: null,
    value: null,
    url: String,
    icon: String,
    size: String,
    label: String,
    center: Boolean,
    isLink: Boolean,
    required: Boolean,
    clickable: Boolean,
    titleWidth: String,
    customClass: {
      type: String,
      default: ''
    },
    customStyle: String,
    arrowDirection: String,
    useLabelSlot: Boolean,
    border: {
      type: Boolean,
      value: true
    },
    titleStyle: String
  },
  methods: {
    onClick: function (event) {
      if (this.isLink && this.url) {
        linkToEasy(this.url)
        return
      }
      this.$emit('cellclick', event.detail)
    }
  }
}
</script>

<style lang="scss" scoped>
  .fun-cell {
    position: relative;
    display: -webkit-flex;
    display: flex;
    box-sizing: border-box;
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
    line-height: 24px;
    color: #323233;
    background-color: #fff;
  }

  .fun-cell:after {
    position: absolute;
    box-sizing: border-box;
    -webkit-transform-origin: center;
    transform-origin: center;
    content: " ";
    pointer-events: none;
    top: auto;
    right: 0;
    bottom: 0;
    left: 16px;
    border-bottom: 1px solid #ebedf0;
    -webkit-transform: scaleY(.5);
    transform: scaleY(.5)
  }

  .fun-cell--borderless:after {
    display: none
  }

  .fun-cell-group {
    background-color: #fff;
  }

  .fun-cell__label {
    margin-top: 3px;
    font-size: 12px;
    line-height: 18px;
    color: #969799;
  }

  .fun-cell__value {
    overflow: hidden;
    text-align: right;
    vertical-align: middle;
    color: #969799;
  }

  .fun-cell__title, .fun-cell__value {
    -webkit-flex: 1;
    flex: 1
  }

  .fun-cell__title:empty, .fun-cell__value:empty {
    display: none
  }

  .fun-cell__left-icon-wrap, .fun-cell__right-icon-wrap {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    height: 24px;
    font-size: 16px;
  }

  .fun-cell__left-icon-wrap {
    margin-right: 5px
  }

  .fun-cell__right-icon-wrap {
    margin-left: 5px;
    color: #969799;
  }

  .fun-cell__left-icon {
    vertical-align: middle
  }

  .fun-cell__left-icon, .fun-cell__right-icon {
    line-height: 24px;
  }

  .fun-cell--clickable.fun-cell--hover {
    background-color: #f2f3f5;
  }

  .fun-cell--required {
    overflow: visible
  }

  .fun-cell--required:before {
    position: absolute;
    content: "*";
    left: 8px;
    font-size: 14px;
    color: #ee0a24;
  }

  .fun-cell--center {
    -webkit-align-items: center;
    align-items: center
  }

  .fun-cell--large {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .fun-cell--large .fun-cell__title {
    font-size: 16px;
  }

  .fun-cell--large .fun-cell__value {
    font-size: 16px;
  }

  .fun-cell--large .fun-cell__label {
    font-size: 14px;
  }
</style>
